# CRMEB：
# 1、用户：查询用户分组——>添加用户分组——>修改刚新增的分组名——>删除刚新增的分组
# 2、客户：添加话术——>修改话术——>删除话术
# 3、用户：添加标签——>删除标签
import pytest
import allure,requests
import uuid
uuid = str(uuid.uuid4()).split('-')[0]
url = "http://121.40.86.4:8899"
pwd = "Aa010903!"
id_list = []
@allure.feature("CRMEB")
class TestCRMEB:
    @pytest.fixture(scope="function")
    def login(self):
        response = requests.post(url = url+"/adminapi/login",json = {"account":"admin","pwd":"Aa010903!","key":"67fdb8403aaab","captchaType":"blockPuzzle","captchaVerification":""})
        token = response.json()['data']['token']
        assert response.status_code == 200
        yield token
    @allure.story("添加用户分组")
    def test_add_group(self,login):
        response = requests.post(url = url+"/adminapi/user/user_group/save.html",headers={"Authori-zation":"Bearer " + str(login)},json={"group_name":"abc" + str(uuid)})
        assert response.status_code == 200
        assert response.json()['msg']=='提交成功'
        #
        response1 = requests.get(url=url + "/adminapi/user/user_group/list?page=1&limit=15",
                                headers={"Authori-zation": "Bearer " + str(login)})
        assert response1.status_code == 200
        assert response1.json()['msg'] == 'success'
        for list_object in response1.json()['data']['list']:
            if list_object['group_name'] == "abc" + str(uuid):
                id_list.append(list_object['id'])
                # self.id = list_object['id']
    @allure.story("修改用户分组")
    def test_update_gruop(self,login):
        response = requests.post(url = url+"/adminapi/user/user_group/save.html",json={"id":id_list[-1],"group_name":"asd"},headers={"Authori-zation":"Bearer " + str(login)})
        assert response.status_code == 200
        assert response.json()['msg'] == '提交成功'

    @allure.story("删除用户分组")
    def test_delete_gruop(self,login):
        response = requests.delete(url = url+"/adminapi/user/user_group/del/"+str(id_list[-1]),headers={"Authori-zation":"Bearer " + str(login)})
        assert response.status_code == 200
        assert response.json()['msg'] == '删除成功!'








